package com.tedu.ds.dsService.controller;

import com.tedu.ds.dsService.pojo.dto.DsServiceParam;
import com.tedu.ds.dsService.pojo.dto.DsServiceQuery;
import com.tedu.ds.dsService.service.DsServiceService;
import com.tedu.ds.base.response.JsonResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
@Slf4j
@RestController
@RequestMapping("/v1/dsService")
@Api(tags = "服务模块")
public class DsServiceController {
    @Autowired
    private DsServiceService dsServiceService;

    @PostMapping("/select")
    @ApiOperation("查询功能")
    public JsonResult select(@RequestBody DsServiceQuery dsServiceQuery){
        return JsonResult.ok(dsServiceService.select(dsServiceQuery));
    }

    @PostMapping("/selectByParentId")
    @ApiOperation("根据父级id查询")
    public JsonResult selectByParentId(@RequestBody DsServiceQuery dsServiceQuery){
        return JsonResult.ok(dsServiceService.selectByParentId(dsServiceQuery));
    }

    @PostMapping("/save")
    @ApiOperation("新增和更新功能")
    public JsonResult save(@RequestBody @Validated DsServiceParam dsServiceParam){
        dsServiceService.save(dsServiceParam);
        return JsonResult.ok();
    }

    @PostMapping("/update/status/{userId}/{status}")
    @ApiOperation("修改服务状态")
    public JsonResult updateStatus(
            @PathVariable Integer userId,@PathVariable Integer status){
        dsServiceService.updateStatus(userId,status);
        return JsonResult.ok();
    }

    @PostMapping("/delete/{id}")
    @ApiOperation("删除功能")
    public JsonResult delete(@PathVariable Integer id){
        dsServiceService.delete(id);
        return JsonResult.ok();
    }
}
